package com.fjd.mapper;

import com.fjd.entity.CustomerInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

@Mapper
public interface ShoppingCustomerInfoMapper {
    /**
     * 根据openid查询用户信息
     * @param openid
     * @return
     */
    @Select("select * from shopping_customer_info where open_id=#{openid}")
    CustomerInfo getByOpenId(String openid);

//    @Select("select customer_id from user_role where account = #{account} and password = #{password}")
//    Integer findByAccount(@Param("account") String account, @Param("password") String password);
    @Select("select customer_id from shopping_customer_info where user_id = #{account} ")
    Integer findByAccount(@Param("account") String account, @Param("password") String password);

    /**
     * 插入用户信息
     * @param customerInfo
     */
    void insert(CustomerInfo customerInfo);

    @Select("select * from shopping_customer_info where customer_id=#{customer_id}")
    CustomerInfo getByCustomerId(Integer customer_id);

    /**
     * 根据customerId查询用户头像和昵称
     * @param customerId
     * @return
     */
    @Select("select customer_avatar, customer_name from shopping_customer_info where customer_id=#{customerId}")
    CustomerInfo getAvatarAndNickname(String customerId);

    /**
     * 根据customerId更新用户信息
     * @param customerInfo
     */
    void updateById(CustomerInfo customerInfo);

    @Select("select customer_name from shopping_customer_info where customer_id=#{customerId}")
    String getUsernameById(String customerId);

    @Select("select customer_avatar from shopping_customer_info where customer_id=#{customerId}")
    String getAvatarById(String customerId);
}
